<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
      <div class="layui-card-body">
        <!-- 头部操作栏 -->
        <form class="layui-form">
          <div class="layui-form lay-header">
            <div class="toolbar">
              <div class="layui-form-item lay-query-content">
                <div class="lay-query-box">
                  <div class="query-lt">
                    <div class="layui-inline">
                      <label class="layui-form-label w-auto">任务编号：</label>
                      <div class="layui-input-inline">
                        <input name="moveDownNumber" class="layui-input" type="text" placeholder="请输入任务编号" />
                      </div>
                    </div>
                
                    <div class="layui-inline">
                      <label class="layui-form-label w-auto">创建时间：</label>
                      <div class="layui-input-inline">
                          <input name="createTime" id="createTime" class="layui-input date-icon" type="text" placeholder="请选择创建时间" style="width: 200px" readonly />
                      </div>
                      <input name="startCreateTime" id="sCreateTime" type="hidden" />
                      <input name="endCreateTime" id="eCreateTime" type="hidden" />
                  </div>
                  </div>
                  <div class="query-rt">
                    <div class="layui-inline">
                      <button type="button" class="layui-btn icon-btn color-green" lay-filter="formSubSearchLog" lay-submit>查询</button>
                      <button class="layui-btn icon-btn color-white" lay-filter="resets" lay-submit type="button">重置</button>
                    </div>
                  </div>
                </div>
              </div>
            </div>
            <div class="lay-btn-rows">
              <div class="lay-btn-box">
                <div class="lay-btn-lt">
                  <!-- <button id="moveDownWarehouseItermBtnAdd" class="layui-btn icon-btn color-reseda" type="button">添加IQC质检任务</button> -->
                </div>
                <div class="lay-btn-rt"></div>
              </div>
            </div>
          </div>
        </form>
        <!-- 表格 -->
        <table class="layui-table" id="moveDownWarehouseItermTable" lay-filter="moveDownWarehouseItermTable"></table>
      </div>
    </div>
  </div>
  
  <!-- 表格操作列 -->
  <script type="text/html" id="moveDownWarehouseItermTableBar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="details">详情</a>
    <a class="layui-btn  layui-btn-xs" lay-event="test">录入质检结果</a>
    <!-- {{# if( d.status=="inspect"){ }} -->
    <!-- <a class="layui-btn layui-btn-xs" lay-event="determine">认领</a> -->
    <!-- {{# } }} -->
    <!-- {{# if( d.status=="inspect"){ }} -->
    <!-- <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="close">作废</a> -->
    <!-- {{# } }} -->
  </script>
  
  <!-- js部分 -->
  <script>
    layui.use(["layer", "form", "table", "admin", "laydate"], function () {
      var $ = layui.jquery;
      var layer = layui.layer;
      var form = layui.form;
      var table = layui.table;
      var config = layui.config;
      var admin = layui.admin;
      var laydate = layui.laydate;
  
      form.render("select");
      laydate.render({
              elem: "#createTime",
              type: "date",
              range: true,
              done: function (value, date, endDate) {
                  if (value) {
                      var dateValue = value.split(" - ");
                      $("input[name='startCreateTime']").val(dateValue[0] + " 00:00:00");
                      $("input[name='endCreateTime']").val(dateValue[1] + " 23:59:59");
                  } else {
                      $("input[name='startCreateTime']").val("");
                      $("input[name='endCreateTime']").val("");
                  }
              },
          });
      // 渲染表格
      var insTb = table.render({
        elem: "#moveDownWarehouseItermTable",
        url: config.base + "enterprisecab/warehouse/admin/moveDownWarehouseIterm/list",
        page: true,
        cellMinWidth: 100,
        cols: [
          [
            { type: "numbers", title: "序号" },
            { field: "moveDownItermNumber", title: "调拨任务明细编号",},
            { field: "moveDownNumber", title: "所属调拨任务" },
            { field: "skuCode", title: "物料编码" },
            { field: "outWarehouseName", title: "调出仓库" },
            { field: "inWarehouseName", title: "调入仓库" },
            { field: "moveNum", title: "数量" },
            { field: "statusName", title: "状态" },
            { field: "creatorName", title: "操作人" },
            { field: "createTime", title: "创建时间" },
            {
              align: "center",
              toolbar: "#moveDownWarehouseItermTableBar",
              title: "操作",
              fixed: "right",
              width: 260
            }
          ]
        ],
        done: function (res, curr, count) {
          //移除按钮
        }
      });
      // 工具条点击事件
      table.on("tool(moveDownWarehouseItermTable)", function (obj) {
        let data = obj.data;
        if (obj.event === "details") {
          if (data) {
            //   data.type = _type;
            admin.putTempData("workOrderQuaTaskInfoData", data);
          } else {
            admin.putTempData("workOrderQuaTaskInfoData", null);
          }
          admin.formOpen({
            type: 1,
            area: ["80%", "85%"],
            style: "font-size: 20px;",
            title: "质检任务详情",
            path: "components/purchase/purQuality/moveDownWarehouseItermDetailForm.html",
            finish: function () {
              table.reload(insTb, {});
            }
          });
        } else if (obj.event === "print") {
          // doPrint(obj);
          // showPrintPurchaseSignForTemplate(data)
        } else if (obj.event === "test") {
          admin.formOpen({
            area: ["90%", "85%"],
            style: "font-size: 20px;",
            title: "录入质检结果",
            path: "components/purchase/purQuality/mymoveDownWarehouseItermForm.html",
            success: function () {
              parentData.data = data;
            }
          });
        }
      });
  
      //监听排序
      table.on("sort(moveDownWarehouseItermTable)", function (obj) {
        table.reload("moveDownWarehouseItermTable", {
          initSort: obj,
          where: {
            sort: obj.field,
            order: obj.type
          }
        });
      });
  
      // 搜索
      form.on("submit(formSubSearchLog)", function (data) {
        insTb.reload({ where: data.field, page: { curr: 1 } }, "data");
      });
  
      // 重置搜索
      form.on("submit(resets)", function (data) {
        insTb.reload({ where: admin.resetSearch(data.field), page: { curr: 1 } }, "data");
        return false;
      });
  
      // 添加按钮点击事件
      $("#moveDownWarehouseItermBtnAdd").click(function () {
        showQualityInspectionTaskModel();
      });
  
      // 添加质检任务弹窗 && 质检任务详情弹窗
      function showQualityInspectionTaskModel(data, _type) {
        //如果是详情 或者是 修改
        if (data) {
          data.type = _type;
          admin.putTempData("workOrderQuaTaskInfoData", data);
        } else {
          admin.putTempData("workOrderQuaTaskInfoData", null);
        }
        if (data) {
        } else {
          title = "添加IQC质检任务";
          admin.formOpen({
            type: 1,
            area: ["80%", "85%"],
            style: "font-size: 20px;",
            title: title,
            path: "components/purchase/purQuality/moveDownWarehouseItermForm.html",
            finish: function () {
              table.reload(insTb, {});
            }
          });
        }
      }
    });
  </script>
  